package com.jtny.nytb.datafilling.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jtny.component.util.BeanUtils;
import com.jtny.nytb.datafilling.dao.InstitutionEquipmentDAO;
import com.jtny.nytb.datafilling.domain.InstitutionEquipmentDO;
import com.jtny.nytb.datafilling.dto.InstitutionEquipmentDTO;
import com.jtny.nytb.datafilling.service.InstitutionEquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 智慧能源中心 - xqx
 * @package com.jtny.nytb.energymonitor.datafilling.service.impl
 * @fileName jtny-nytb-energymonitor-carbonemission-server
 * @Copyright© 2024 jtny
 * @Date 2024/4/9
 * 江投能源技术研究院 版权所有
 */
@Service
public class InstitutionEquipmentServiceImpl extends ServiceImpl<InstitutionEquipmentDAO, InstitutionEquipmentDO> implements InstitutionEquipmentService {
    @Autowired
    private InstitutionEquipmentDAO institutionEquipmentDAO;

    @Override
    public InstitutionEquipmentDTO getByEquipmentId(Long equipmentId) {
        LambdaQueryWrapper<InstitutionEquipmentDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(InstitutionEquipmentDO::getEquipmentId, equipmentId)
                .eq(InstitutionEquipmentDO::getInstitution, "工商业用电").last("limit 1");
        InstitutionEquipmentDO institutionEquipmentDO = institutionEquipmentDAO.selectOne(queryWrapper);
        if (institutionEquipmentDO != null) {
            return BeanUtils.copyToObject(institutionEquipmentDO, InstitutionEquipmentDTO.class);
        }
        return null;
    }

    @Override
    public List<InstitutionEquipmentDTO> getByEquipmentIds(List<Long> equipmentIds) {
        List<InstitutionEquipmentDO> institutionEquipmentDOS = institutionEquipmentDAO.selectBatchIds(equipmentIds);
        if (CollUtil.isNotEmpty(institutionEquipmentDOS)) {
            return BeanUtils.copyToList(institutionEquipmentDOS, InstitutionEquipmentDTO.class);
        }
        return new ArrayList<>();
    }
}
